package com.baturu.ford.carvin.dal;

import com.baturu.offlineFord.dto.SubGroupDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @Author: chenjiahao
 * @Time: 2019/1/17
 */
public interface DealCarTypeDAO {
    @Select({"SELECT max(id) from ford_epc_car_type"})
    Integer queryMaxId();

    @Select({"SELECT begin,end FROM ford_epc_car_type WHERE id = #{id} limit 1"})
    Map<String,String> queryDate(@Param("id") Integer id);

    @Update({"UPDATE ford_epc_car_type set begin = #{b} ,end = #{e} WHERE id = #{id}"})
    void update(@Param("b") String b, @Param("e") String e, @Param("id") Integer id);

    @Update({"update ford_epc_car_type set end = '99999999' where end is null or end = ''"})
    void updateEnd();
    @Update({"update ford_epc_car_type set begin = '' where begin is null "})
    void updateBegin();


    @Select({"SELECT max(id) FROM ford_epc_parts_subgroup"})
    Integer queryMaxSubGroupId();

    @Select({"SELECT id,textCondition FROM ford_epc_parts_subgroup WHERE id = #{id}"})
    SubGroupDTO querySubGroup(@Param("id") Integer id);

    @Select({"SELECT idx FROM ford_epc_text WHERE textIdx = #{id}"})
    String queryIdx(@Param("id") String id);

    @Insert({"<script>INSERT INTO ford_epc_parts_subgroup (id,dealTextCondition) values" ,
            "<foreach item = 'dto' collection = 'dtos' open = '(' separator = '),(' close = ')'>",
            "#{dto.id},#{dto.dealTextCondition}",
            "</foreach>",
            "on duplicate key update dealTextCondition = values(dealTextCondition)",
            "</script>"})
    void updateDealTextCondition(@Param("dtos") List<SubGroupDTO> subGroupDTOs);
}
